package cn.wx.service;


import cn.wx.entity.UserInfo;
import cn.wx.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户信息管理视图层
 */
@RestController
@RequestMapping("/userInfo")
@Api(tags = "用户信息管理")
public class UserInfoRest {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 分页获取所有的用户
     * @return
     */
    @ApiOperation(value = "分页获取所有的用户")
    @PostMapping("/queryPage")
    public Page<UserInfo> queryUserPage(@PageableDefault Pageable pageable) {
        Page<UserInfo> userInfos = userInfoService.queryUserPage(pageable.getPageNumber(), pageable.getPageSize());
        return userInfos;
    }

    /**
     * 添加或者修改用户
     */
    @ApiOperation(value = "添加或者修改用户")
    @PostMapping("/saveOrUpdate")
    public void saveOrUpdate(@RequestBody UserInfo userInfo) {
        userInfoService.saveOrUpdate(userInfo);
    }

    /**
     * 删除用户
     */
    @ApiOperation(value = "删除用户")
    @DeleteMapping("/delete")
    public void deleteUserById(@RequestParam("id") Long id) {
        userInfoService.deleteUserById(id);
    }
}